package com.tianqu.tms.www.check.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.entity.TransferAcceptedInfo;

public class CheckCarPrintWheatherPrintAjaxAction extends TmsAjaxAction {

	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		String serial = request.getParameter("serial");
		String type = request.getParameter("type");
		String str = "";
		TxController controller = TxController.getTxController();
		try {
			TransferAcceptedInfo accept = new TransferAcceptedInfo();
			accept = accept.getAcceptInfoBySerial(serial, "");
			
			
			String carOwner = accept.getCarOwner();
			if(carOwner == null)
			{
				carOwner = "0";
			}
			if("2".equals(type))
			{
				//查验表
				if(accept.getCy_printTime()!=null)
				{
					//type,是否存在，流水号，carowner，号牌种类，车牌号
					str = type+",1,"+accept.getSerial()+","+carOwner+","+accept.getCy_cardType()+","+accept.getLicensePlate();
				}else{
					str = type+",2,"+accept.getSerial()+","+carOwner+","+accept.getCy_cardType()+","+accept.getLicensePlate();
				}
			}
			if("1".equals(type))
			{
				//流程表
				if(accept.getLc_printTime()!=null)
				{
					//type,是否存在，流水号，carowner，号牌种类，车牌号
					str = type+",1,"+accept.getSerial()+","+carOwner+","+accept.getCy_cardType()+","+accept.getLicensePlate();
				}else{
					str = type+",2,"+accept.getSerial()+","+carOwner+","+accept.getCy_cardType()+","+accept.getLicensePlate();
				}
			}
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
		}
		
		String responseText = str.toString();
		responseValues(response, responseText, TEXT);
	}
}
